<?php

include_once "funct.php";

if (!isset($_GET["id"]))
	iesire();
$room = room(clean($_GET["id"]));
$user = user($_SESSION["user"]);
$continut = "";
if ($room !== false) {
	if ($room["user"] != $user["id"] && $room["user2"] == -1)
		mysql_query("update " . $db["rooms"] . " set end='" . a_ceas(5 * 60 * 60) . "', start='" . ceas() . "', user2='" . $user["id"] . "' where id='" . $room["id"] . "'");
	if ($room["user"] != $user["id"] && $room["user2"] != -1 && $room["user2"] != $user["id"]) //ma asigur ca nu intra altcineva in afara de cei doi jucatori in batalie
		iesire();
	if ($room["user2"] == -1)
		$juc["name"] = "";
	elseif ($room["user"] != $user["id"])
		$juc = user($room["user"]);
	else
		$juc = user($room["user2"]);
	if ($juc === false)
		$juc["name"] = "";
	elseif ($juc["name"] != "")
		$juc["name"] = "vs " . $juc["name"];
	$continut.='<div class="titlu" id="titlu">' . $room["name"] . ' <span>' . $juc["name"] . '</span></div>';
	$mess = mess($room["id"]);
	$continut.='<div class="continut_s" id="continut_s" style="height:280pt;" id="mess">' . $mess . '</div>';
	$continut.='<form action="javascript:adauga(\'message\');">
					<textarea id="message" class="input" style="position:relative; margin-top:30pt; height:35pt; width:400pt;" placeholder="' . $lang["replica"] . '..."></textarea></br>
					<input type="submit" class="buton" style="position: relative; marin:0 auto;" value="' . $lang["Send"] . '" />
					<a href="delete_b.php?id=' . $room["id"] . '"><input type="button" class="buton" style="position: relative; marin:0 auto;" value="' . $lang["g_out"] . '" /></a>
				</form>';
	$rezultat = mysql_query("select * from " . $db["messages"] . " where room='" . $room["id"] . "' order by date desc limit 0,1");
	$rand = mysql_fetch_array($rezultat);
	if (count($rand) > 1)
		$ceas = $rand["date"];
	else
		$ceas = ceas();
	echo $continut;
}
?>
